home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example External Tools / ProcessTool / Service.cp < prev    next >
Encoding:
Text File  |  1998-06-04  |  4.0 KB  |  148 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        Service.cp
  3.  *
  4.  *    Contains:    xxx put contents here xxx
  5.  *
  6.  *    Written by:    Rick Violet
  7.  *
  8.  *    Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  9.  *
  10.  *    Change History (most recent first):
  11.  *
  12.  *         <2>     1/27/94    BD        String utilities moved to TextUtils.h from         Packages.h.
  13.  *        <1+>     1/27/94    BD        String utilities moved to TextUtils.h from Packages.h.
  14.  *        <5+>    11/19/92    RV        
  15.  *                11/18/92    RV        xxx put comment here xxx
  16.  *
  17.  *    To Do:
  18.  */
  19.  
  20. #ifndef        __Service__
  21. #include        "Service.h"
  22. #endif
  23.  
  24. #ifndef        __Application__
  25. #include        "Application.h"
  26. #endif
  27.  
  28. #ifndef        __RequestDispatcher__
  29. #include        "RequestDispatcher.h"
  30. #endif
  31.  
  32. #ifndef        __TEXTUTILS__
  33. #include        <TextUtils.h>
  34. #endif
  35.  
  36. //—————————————————————————————————————————————————————————————————————————————————————
  37. //                                Global Variables
  38. //—————————————————————————————————————————————————————————————————————————————————————
  39. extern    RequestDispatcher*        gTheRequestDispatcher;
  40. extern    Application*            gTheApplication;
  41.  
  42. //—————————————————————————————————————————————————————————————————————————————————————
  43. //    Service::Service    -    constructor.
  44. //—————————————————————————————————————————————————————————————————————————————————————
  45. Service::Service( char* pSrvName )
  46. {            
  47.     if( pSrvName != nil )
  48.     {
  49.         fSrvNameText = new char[ strlen( pSrvName ) + 1 ];
  50.         if( fSrvNameText != nil )
  51.         {
  52.             strcpy( fSrvNameText, pSrvName );
  53.         }
  54.     }
  55.     else
  56.     {
  57.         fSrvNameText = nil;
  58.     }    
  59. }
  60.  
  61. //—————————————————————————————————————————————————————————————————————————————————————
  62. //    Service::~Service    -    destructor.
  63. //—————————————————————————————————————————————————————————————————————————————————————
  64. Service::~Service()
  65. {
  66.     if( fSrvNameText != nil )
  67.     {
  68.         delete fSrvNameText;
  69.     }
  70. }
  71.  
  72. //—————————————————————————————————————————————————————————————————————————————————————
  73. //    Service::CanDoService    -    return true if we can handle the Service indicated.
  74. //—————————————————————————————————————————————————————————————————————————————————————
  75. Boolean
  76. Service::CanDoService( char* pServiceName )
  77. {    
  78.     short    tResult;
  79.     
  80.     if( fSrvNameText != nil )    
  81.     {
  82.         tResult = relstring( pServiceName, fSrvNameText, false, true );
  83.         if( tResult == 0 )
  84.         {
  85.             return true;
  86.         }
  87.     }
  88.     return false;
  89. }
  90.  
  91. //—————————————————————————————————————————————————————————————————————————————————————
  92. //    Service::ProcessRequest    -    implement the Request from V.U.
  93. //
  94. //        This method is called by the Dispatcher to implement the requested service.
  95. //        Override this method within your own subclass to implement the Service.
  96. //        Be sure to call Request::CheckForCancel frequently to allow for canceling.
  97. //        If Request::CheckForCancel returns true, then stop processing, and return 
  98. //        immeadiately.
  99. //        Otherwise continue processing.
  100. //
  101. //—————————————————————————————————————————————————————————————————————————————————————
  102. OSErr
  103. Service::ProcessRequest( Request* pReq )
  104. {
  105.         //————    We do nothing but beep thrice
  106.     SysBeep( 1 );
  107.     SysBeep( 1 );
  108.     SysBeep( 1 );
  109.     
  110.         //————    and return the word 'beeped' to the script
  111.     pReq->SetReturnValue( "beeped" );
  112.     
  113.         //————    no errors encountered
  114.     return noErr;
  115. }
  116.  
  117. //—————————————————————————————————————————————————————————————————————————————————————
  118. //    Service::GetServiceNameText    
  119. //—————————————————————————————————————————————————————————————————————————————————————
  120. ScriptValue*
  121. Service::GetServiceNameText()
  122. {
  123.     VUString*    tTextVal;
  124.     
  125.     tTextVal = new VUString( fSrvNameText );
  126.     
  127.     return tTextVal;
  128. }
  129.  
  130. //—————————————————————————————————————————————————————————————————————————————————————
  131. //    Service::CheckForCancel    -    Check for cancel requests and return true
  132. //            if the current request has been canceled
  133. //—————————————————————————————————————————————————————————————————————————————————————
  134. Boolean
  135. Service::CheckForCancel( Request* pReq )
  136. {
  137.     Boolean    tHasBeenCanceled = false;
  138.     
  139.         //————    Spin the cursor for Humans to see
  140.     gTheApplication->SpinTheCursor();
  141.  
  142.         //————    Reset all TimeOut counters which are due
  143.     gTheRequestDispatcher->ResetAllTimeOutCounters();
  144.     
  145.         //————    Check to see if we have received a Cancel message for this request
  146.     return pReq->HasBeenCanceled();
  147. }
  148.